package znbkTestPaperRdqh.fragmentAdapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import znbkTestPaperRdqh.fragment.WeekAscensionPaperFragment;

import static znbkTestPaperRdqh.activity.WeekAscensionPaperActivity.mEntityRdqh;

/**
 * Created by Administrator on 2018\4\2 0002.
 */

public class WeekAscensionPaperFragmentAdapter extends FragmentPagerAdapter {

    private long flag = 0;
    private FragmentManager fm;

    public WeekAscensionPaperFragmentAdapter(FragmentManager fm) {
        super(fm);
        this.fm = fm;
    }
    @Override
    public int getCount() {
        int sumCount = 0 ;
        if(mEntityRdqh.getModelSinglePaperInfo() != null){
            sumCount = mEntityRdqh.getModelSinglePaperInfo().getModelTKQueList().size();
        }
        return sumCount;
    }
    @Override
    public Fragment getItem(int position) {
        return WeekAscensionPaperFragment.newInstance(position);
    }

    @Override
    public long getItemId(int position) {
        return position + flag;
    }

    public void clearFragmentsCache(){
        flag = System.currentTimeMillis();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Fragment fragment = (Fragment) super.instantiateItem(container,
                position);
        fm.beginTransaction().show(fragment).commit();
        return fragment;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        Fragment fragment = (Fragment) object;
        fm.beginTransaction().hide(fragment).commit();
    }

}